#pragma once
#include <stdint.h>
#include <vector>

typedef struct
{
    unsigned long long user_time;
    unsigned long long nice_time;
    unsigned long long system_time;
    unsigned long long idle_time;
    unsigned long long iowait_time;
    unsigned long long irq_time;
    unsigned long long softirq_time;
    unsigned long long steal_time;
    unsigned long long guest_time;
    unsigned long long guest_nice_time;
    // 计算值
    float used_time;
    float total_time;
    float usage;
    float io_usage;
} cpuTime_t;

typedef struct
{
    cpuTime_t cpu_all;
    unsigned long cpu_num;
    unsigned long long read_count;
    std::vector<cpuTime_t> cpus;
} sysCpuTime_t;

class MonitorCpu
{
public:
    MonitorCpu();
    ~MonitorCpu();
    long get_cpu_num();

    // 获取系统cpu时间
    sysCpuTime_t* updae_cpu_time(bool opt_cal_usage = true);
    int cal_cpu_usage(sysCpuTime_t* prev, sysCpuTime_t* curr);
    void show_cpu_usage(sysCpuTime_t* curr);
    unsigned long get_cpu_time(uint32_t cpu_id = 0xfffffff);

private:
    std::vector<sysCpuTime_t> sysCpuTime_;
    sysCpuTime_t* curr_sysCpuTime_;
    const char FILE_PROC_STAT_[32] = "/proc/stat";
};
